package com.zyh.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zyh.entity.Record;
import com.zyh.service.IRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zhang
 * @since 2022-05-04
 */
@RestController
@RequestMapping("/record")
public class RecordController {
    @Autowired
    IRecordService recordService;

    @GetMapping("/selectByPage")
    public IPage<Record> selectByPage(@RequestBody Page page){
        return recordService.page(page);
    }
    @GetMapping("/selectByStuId")
    public List<Record> selectByStuId(Integer id){
        QueryWrapper<Record> wrapper = new QueryWrapper<>();
        wrapper.eq("stuId",id);
        return recordService.list(wrapper);
    }
    @GetMapping("/selectById")
    public Record selectById(Integer id){
        return recordService.getById(id);
    }
    @PutMapping("/update")
    public void update(@RequestBody Record record){
        recordService.updateById(record);
    }
    @PostMapping("/insert")
    public void insert(@RequestBody Record record){
        record.setCreateDate(LocalDateTime.now());
        recordService.save(record);
    }
    @DeleteMapping("/deleteById")
    public void delete(Integer id){
        recordService.removeById(id);
    }
}

